
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Enumeration;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * mainScreen.java
 *
 * Created on Nov 22, 2011, 12:27:52 PM
 */
/**
 *
 * @author Thomas
 */
public class mainScreen extends javax.swing.JPanel {

    /** The game. */
    private static GameInterface game;
    /** The leader. */
    private Leader leader;
    /** The wagon. */
    private Wagon wagon;
    /** The current pace. */
    private Pace currPace;
    /** The current ration. */
    private Rations currRation;
    /** The map class. */
    private Map mapClass;
    /** The wagon load. */
    private Inventory wagonLoad;
    private TurnListener listen;

    /** Creates new form mainScreen */
    public mainScreen(GameInterface face) {
        initComponents();


        displayPanel.setBackground(Color.black);
        setBackground(Color.yellow);
        barebones.setBackground(Color.yellow);
        meager.setBackground(Color.yellow);
        filling.setBackground(Color.yellow);
        leisurely.setBackground(Color.yellow);
        steady.setBackground(Color.yellow);
        grueling.setBackground(Color.yellow);

        game = face;
        wagon = game.getWagon();
        leader = wagon.getLeader();
        wagonLoad = wagon.getWagonLoad();
        currPace = wagon.getCurrPace();
        currRation = wagon.getCurrRations();
        mapClass = face.getMap();
        listen = new TurnListener();

        takeTurn.addActionListener(listen);
        save.addActionListener(new SaveListener());

        if (currRation == Rations.BareBones) {
            barebones.setSelected(true);
        } else if (currRation == Rations.Meager) {
            meager.setSelected(true);
        } else if (currRation == Rations.Filling) {
            filling.setSelected(true);
        }

        if (currPace == Pace.Grueling) {
            grueling.setSelected(true);
        } else if (currPace == Pace.Leisurely) {
            leisurely.setSelected(true);
        } else if (currPace == Pace.Steady) {
            steady.setSelected(true);
        }

        money.setText("$" + Integer.toString(leader.getMoney()));
        distanceToNext.setText(Integer.toString(mapClass.getDistanceToNext()));
        distanceTraveled.setText(Integer.toString(mapClass.getDistanceMoved()));
        currLocation.setText(mapClass.getCurrLocation().getName());
        lastLocation.setText(mapClass.getLastLoc().getName());
        currentFood.setText(Integer.toString(wagonLoad.getQuantity(3)));
        currentDate.setText(wagon.getDateString());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rations = new javax.swing.ButtonGroup();
        pace = new javax.swing.ButtonGroup();
        leisurely = new javax.swing.JRadioButton();
        grueling = new javax.swing.JRadioButton();
        steady = new javax.swing.JRadioButton();
        barebones = new javax.swing.JRadioButton();
        rationText = new javax.swing.JLabel();
        meager = new javax.swing.JRadioButton();
        filling = new javax.swing.JRadioButton();
        paceText = new javax.swing.JLabel();
        takeTurn = new javax.swing.JButton();
        money = new javax.swing.JLabel();
        currentFood = new javax.swing.JLabel();
        moneyText = new javax.swing.JLabel();
        distanceTraveled = new javax.swing.JLabel();
        foodText = new javax.swing.JLabel();
        distanceText = new javax.swing.JLabel();
        save = new javax.swing.JButton();
        lblCurrentLocation = new javax.swing.JLabel();
        lblLastLocation = new javax.swing.JLabel();
        currLocation = new javax.swing.JLabel();
        lastLocation = new javax.swing.JLabel();
        lblDistanceToNext = new javax.swing.JLabel();
        distanceToNext = new javax.swing.JLabel();
        displayPanel = new javax.swing.JPanel();
        huntButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        currentDate = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(697, 410));

        pace.add(leisurely);
        leisurely.setText("Leisurely");

        pace.add(grueling);
        grueling.setText("Grueling");

        pace.add(steady);
        steady.setText("Steady");

        rations.add(barebones);
        barebones.setText("Bare Bones");

        rationText.setText("Rations:");

        rations.add(meager);
        meager.setText("Meager");

        rations.add(filling);
        filling.setText("Filling");

        paceText.setText("Pace:");

        takeTurn.setText("Take Turn");

        money.setText("0");

        currentFood.setText("0");

        moneyText.setText("Money:");

        distanceTraveled.setText("0");

        foodText.setText("Current Food:");

        distanceText.setText("Distance Traveled:");

        save.setText("Save");

        lblCurrentLocation.setText("Current Location:");

        lblLastLocation.setText("Last Location:");

        currLocation.setText("Independence, MO");

        lastLocation.setText("N/A");

        lblDistanceToNext.setText("Distance to Next:");

        distanceToNext.setText("0");

        javax.swing.GroupLayout displayPanelLayout = new javax.swing.GroupLayout(displayPanel);
        displayPanel.setLayout(displayPanelLayout);
        displayPanelLayout.setHorizontalGroup(
            displayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 434, Short.MAX_VALUE)
        );
        displayPanelLayout.setVerticalGroup(
            displayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 265, Short.MAX_VALUE)
        );

        huntButton.setText("Hunt");
        huntButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                huntButtonActionPerformed(evt);
            }
        });

        jLabel1.setText("Current Date:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(lblCurrentLocation)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(10, 10, 10)
                                    .addComponent(currLocation, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addComponent(lblLastLocation)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(10, 10, 10)
                                    .addComponent(lastLocation, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addComponent(jLabel1)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(currentDate)))
                        .addGap(30, 30, 30)
                        .addComponent(displayPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(moneyText)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(money, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(foodText)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(currentFood, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(19, 19, 19))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblDistanceToNext)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(distanceToNext, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(distanceText)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(distanceTraveled, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(grueling)
                    .addComponent(steady)
                    .addComponent(leisurely)
                    .addComponent(paceText)
                    .addComponent(rationText)
                    .addComponent(filling)
                    .addComponent(meager)
                    .addComponent(barebones)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(huntButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(save, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(takeTurn, javax.swing.GroupLayout.Alignment.LEADING)))
                .addGap(34, 34, 34))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(displayPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(huntButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(save)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(takeTurn))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(rationText)
                                    .addComponent(lblCurrentLocation))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(currLocation)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(lblLastLocation)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lastLocation)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel1))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(barebones)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(meager)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(filling)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(7, 7, 7)
                                        .addComponent(paceText)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(leisurely)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(steady)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(grueling)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addGap(6, 6, 6)
                                        .addComponent(currentDate)
                                        .addGap(176, 176, 176)))
                                .addGap(54, 54, 54))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(lblDistanceToNext)
                                    .addComponent(distanceToNext))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(distanceText)
                                    .addComponent(distanceTraveled))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(foodText)
                                    .addComponent(currentFood))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(moneyText)
                                    .addComponent(money))))
                        .addGap(32, 32, 32)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void huntButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_huntButtonActionPerformed
        huntScreen screen = new huntScreen(game);
        huntingOptions options = new huntingOptions(screen);
        JPanel panel = options;
        panel.setSize(new Dimension(700, 795));
        game.changeDisplay(panel);
    }//GEN-LAST:event_huntButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton barebones;
    private javax.swing.JLabel currLocation;
    private javax.swing.JLabel currentDate;
    private javax.swing.JLabel currentFood;
    private javax.swing.JPanel displayPanel;
    private javax.swing.JLabel distanceText;
    private javax.swing.JLabel distanceToNext;
    private javax.swing.JLabel distanceTraveled;
    private javax.swing.JRadioButton filling;
    private javax.swing.JLabel foodText;
    private javax.swing.JRadioButton grueling;
    private javax.swing.JButton huntButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel lastLocation;
    private javax.swing.JLabel lblCurrentLocation;
    private javax.swing.JLabel lblDistanceToNext;
    private javax.swing.JLabel lblLastLocation;
    private javax.swing.JRadioButton leisurely;
    private javax.swing.JRadioButton meager;
    private javax.swing.JLabel money;
    private javax.swing.JLabel moneyText;
    private javax.swing.ButtonGroup pace;
    private javax.swing.JLabel paceText;
    private javax.swing.JLabel rationText;
    private javax.swing.ButtonGroup rations;
    private javax.swing.JButton save;
    private javax.swing.JRadioButton steady;
    private javax.swing.JButton takeTurn;
    // End of variables declaration//GEN-END:variables

    // This method returns the selected radio button in a button group
    /**
     * Gets the selection.
     *
     * @param group the group
     * @return the selection
     */
    public static JRadioButton getSelection(ButtonGroup group) {
        for (Enumeration e = group.getElements(); e.hasMoreElements();) {
            JRadioButton b = (JRadioButton) e.nextElement();
            if (b.getModel() == group.getSelection()) {
                return b;
            }
        }
        return null;
    }

    public static void randEventPopup(String eventOutcome) {
        JOptionPane.showMessageDialog(game, eventOutcome);
    }

    /**
     * The listener interface for receiving turn events.
     * The class that is interested in processing a turn
     * event implements this interface, and the object created
     * with that class is registered with a component using the
     * component's addTurnListener method. When
     * the turn event occurs, that object's appropriate
     * method is invoked.
     *
     * @see TurnEvent
     */
    private class TurnListener implements ActionListener {

        /* (non-Javadoc)
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
         */
        public void actionPerformed(ActionEvent e) {
            //        	enterShop.setEnabled(false);

            String p = getSelection(pace).getText();
            if (p.equals("Leisurely")) {
                wagon.setCurrPace(Pace.Leisurely);
            } else if (p.equals("Steady")) {
                wagon.setCurrPace(Pace.Steady);
            } else {
                wagon.setCurrPace(Pace.Grueling);
            }

            p = getSelection(rations).getText();
            if (p.equals("Bare Bones")) {
                wagon.setCurrRations(Rations.BareBones);
            } else if (p.equals("Meager")) {
                wagon.setCurrRations(Rations.Meager);
            } else {
                wagon.setCurrRations(Rations.Filling);
            }

            money.setText("$" + Integer.toString(leader.getMoney()));

            mapClass.takeTurn(wagon);

            wagon = mapClass.getWagon();

            wagon.nextDay();
            currentDate.setText(wagon.getDateString());

            currLocation.setText(mapClass.getCurrLocation().getName());
            lastLocation.setText(mapClass.getLastLoc().getName());
            distanceToNext.setText(Integer.toString(mapClass.getDistanceToNext()));
            wagonLoad = wagon.getWagonLoad();
            currentFood.setText(Integer.toString(wagonLoad.getQuantity(3)));
            distanceTraveled.setText(Integer.toString(mapClass.getDistanceMoved()));

            validate();

            if (mapClass.getCurrLocation() != Map.na && mapClass.getCurrLocation().myShop != null) {
                game.setWagon(wagon);
                game.setMap(mapClass);
                Object[] options = {"Enter shop",
                    "Continue on the trail"};
                int n = JOptionPane.showOptionDialog(game,
                        "You have arrived at " + mapClass.getCurrLocation().getName()
                        + "\nWhat would you like do?",
                        "Town",
                        JOptionPane.YES_NO_OPTION,
                        JOptionPane.INFORMATION_MESSAGE,
                        null,
                        options,
                        options[0]);

                if (n == 0) {
                    JPanel panel = new generalStore(mapClass.getCurrLocation().myShop, game);
                    panel.setSize(new Dimension(450, 300));
                    game.changeDisplay(panel);
                } else if (n == 1) {
                }
                //            	enterShop.setEnabled(true);
            }

            if (mapClass.getCurrLocation().isRiver()) {
                Object[] options = {"Caulk and Float",
                    "Take Ferry ($200)",
                    "Ford the River"};
                int n = JOptionPane.showOptionDialog(game,
                        "You have approached the " + mapClass.getCurrLocation().getName()
                        + "\nWhat do you do?",
                        "River Crossing",
                        JOptionPane.YES_NO_CANCEL_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        null,
                        options,
                        options[0]);

                // Handle choices, can use switch statement instead
                while (n == -1) {
                    if (n == -1) {
                        JOptionPane.showMessageDialog(game, "You must pick a choice!");
                        n = JOptionPane.showOptionDialog(game,
                                "You have approached the " + mapClass.getCurrLocation().getName()
                                + "\nWhat do you do?",
                                "River Crossing",
                                JOptionPane.YES_NO_CANCEL_OPTION,
                                JOptionPane.QUESTION_MESSAGE,
                                null,
                                options,
                                options[0]);
                    }
                }

                if (n == 0) {
                    if (mapClass.getRiver().checkFloat()) {
                        JOptionPane.showMessageDialog(game, "Congratulations!  "
                                + "You have flirted with danger but still made it safely!");
                    } else if (!mapClass.getRiver().checkFloat()) {
                        int lostItemCount = (int) ((Math.random() * 40));
                        if (wagonLoad.getQuantity(3) < lostItemCount) {
                            JOptionPane.showMessageDialog(game, "Your wagon has tipped over and "
                                    + "You have lost any food you had.");
                        } else {
                            JOptionPane.showMessageDialog(game, "Your wagon has tipped over and "
                                    + "you have lost " + lostItemCount + " pounds of food.");
                        }
                        wagonLoad.remove(new Food(lostItemCount));
                        currentFood.setText(Integer.toString(wagonLoad.getQuantity(3)));
                    }
                } else if (n == 1) {
                    if (mapClass.getRiver().checkFerry()) {
                        leader.setMoney(leader.money - 200); //ferry costs $200
                        money.setText("$" + Integer.toString(leader.getMoney()));
                        JOptionPane.showMessageDialog(game, "You have paid $200 to cross "
                                + "the river safely.");
                    }
                } else if (n == 2) {
                    if (mapClass.getRiver().checkFord()) {
                        JOptionPane.showMessageDialog(game, "Congratulations!  "
                                + "You have flirted with danger but still made it safely!");
                    } else if (!mapClass.getRiver().checkFord()) {
                        int lostItemCount = (int) ((Math.random() * 70) + 30);
                        if (wagonLoad.getQuantity(3) < lostItemCount) {
                            JOptionPane.showMessageDialog(game, "Your wagon has tipped over and "
                                    + "You have lost any food you had.");
                        } else {
                            JOptionPane.showMessageDialog(game, "Your wagon has tipped over and "
                                    + "you have lost " + lostItemCount + " pounds of food.");
                        }
                        wagonLoad.remove(new Food(lostItemCount));
                        currentFood.setText(Integer.toString(wagonLoad.getQuantity(3)));
                    }
                }
            }

            // Check for fork here
            if (mapClass.getCurrLocation().hasFork()) {
                Object[] options = {"Green River Crossing",
                    "Fort Bridger"};

                int n = JOptionPane.showOptionDialog(game,
                        "There's a fork in the road; you may\n"
                        + "1. Proceed to the Green River Crossing (less distance)\n"
                        + "2. Go to Fort Bridger (farther, but you can buy supplies)",
                        "Fork",
                        JOptionPane.YES_NO_OPTION,
                        JOptionPane.INFORMATION_MESSAGE,
                        null,
                        options,
                        options[0]);

                if (n == 0) {
                    // Do nothing, everything's staying the same
                } else {
                    // Change all new locations for the fork
                    mapClass.takeFork();
                }
            }

            // Check for fork here
            if (mapClass.getCurrLocation().hasFork()) {
                Object[] options = {"Green River Crossing",
                    "Fort Bridger"};

                int n = JOptionPane.showOptionDialog(game,
                        "There's a fork in the road; you may\n"
                        + "1. Proceed to the Green River Crossing (less distance)\n"
                        + "2. Go to Fort Bridger (farther, but you can buy supplies)",
                        "Fork",
                        JOptionPane.YES_NO_OPTION,
                        JOptionPane.INFORMATION_MESSAGE,
                        null,
                        options,
                        options[0]);

                if (n == 0) {
                    // Do nothing, everything's staying the same
                } else {
                    // Change all new locations for the fork
                    mapClass.takeFork();
                }
            }

            if (mapClass.getCurrLocation().isLast() == true) {
                JOptionPane.showMessageDialog(null, "You've reached Oregon!");
                takeTurn.setEnabled(false);
            }
        }
    }

    private class SaveListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            String fileName = JOptionPane.showInputDialog(game, "Enter the name of your save game:");

            try {
                FileWriter fstream = new FileWriter(fileName + ".txt");
                BufferedWriter out = new BufferedWriter(fstream);

                out.write(getSelection(pace).getText());
                out.newLine();
                out.write(getSelection(rations).getText());
                out.newLine();
                out.write(leader.getName());
                out.newLine();
                out.write(leader.getMyProfession().toString());
                out.newLine();
                out.write(Integer.toString(leader.getMoney()));
                out.newLine();
                for (int i = 0; i < wagon.getMembers().size(); i++) {
                    out.write(wagon.getMembers().get(i).getName());
                    out.newLine();
                }
                out.write(Integer.toString(mapClass.getDistanceMoved()));
                out.newLine();
                for (int i = 0; i < wagonLoad.getItems().size(); i++) {
                    out.write(Integer.toString(wagonLoad.getItems().get(i).getQuantity()));
                    out.newLine();
                }

                out.close();
            } catch (Exception d) {
                System.err.println("Error: " + d.getMessage());
            }
            int n = JOptionPane.showConfirmDialog(
                    game,
                    "Would you like to continue the game?",
                    "Continue or Exit",
                    JOptionPane.YES_NO_OPTION);

            if (n == JOptionPane.NO_OPTION) {
                System.exit(0);
            }
        }
    }
}
